package lab03.test09;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AIR on 2017/12/28.
 */
public class Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();  //存储每一个字段
        String path = "F:\\book.txt";
        File bookInformation = new File(path);
        try {
            bookInformation.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        BufferedReader reader = null;
        BufferedWriter writer = null;
        try {
            reader = new BufferedReader(new FileReader("F:\\b.txt"));
            writer = new BufferedWriter(new FileWriter("F:\\book.txt"));
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                } else {
                    String[] strings = line.split(" ");
                    for (int i = 0; i < strings.length; i++) {
                        list.add(strings[i]);
                    }
                }
            }
            for (int i = 0; i < list.size(); i++) {  //更改指定的基本信息并将其输出
                if (list.get(i).equals("29.8")) {
                    writer.write("59.8");
                    writer.write("      ");
                } else if (list.get(i).equals("42.5")) {
                    writer.write("62.5");
                    writer.write("      ");
                } else {
                    writer.write(list.get(i));
                    writer.write("      ");
                    if (i % 5 == 0) {      //按照指定格式输出
                        writer.newLine();
                    }
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
